package com.isoft.airportsystem.service.impl;


import com.isoft.airportsystem.entity.CKLS.CNTR;
import com.isoft.airportsystem.entity.CKLS.DFLT_CKLS;
import com.isoft.airportsystem.entity.META;
import com.isoft.airportsystem.mapper.CKLSMapper;
import com.isoft.airportsystem.mapper.MetaMapper;
import com.isoft.airportsystem.service.CKLSService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class CKLSServiceImpl implements CKLSService {
    @Resource
    private CKLSMapper cklsMapper;

    @Resource
    private MetaMapper metaMapper;

    @Override
    public Integer add(DFLT_CKLS dfltCkls, META meta) {
        String cntrid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
        String metaid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
        cklsMapper.add(dfltCkls, cntrid, metaid);
        if(dfltCkls.getCkls().getCntr()!=null){
            for (CNTR cntr : dfltCkls.getCkls().getCntr()) {
                addCNTR(cntr,cntrid);
            }
        }
        metaMapper.add(meta,metaid);
        return null;
    }

    @Override
    public Integer addCNTR(CNTR cntr, String cntrid) {
        return cklsMapper.addCNTR(cntr, cntrid);
    }
}
